package com.fs.system.college_admin.controller;

import com.fs.system.college_admin.service.ActiveCreditService;
import com.fs.system.common.ResponseData;
import com.fs.system.student.domain.ActCredit;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/collegeAdminActiveCredit")
public class ActiveCreditController {

    @Resource
    private ActiveCreditService activeCreditService;

    @PostMapping("/addActiveCredit")
    public ResponseData addActiveType(@RequestBody ActCredit actCredit) {
        activeCreditService.addActiveCredit(actCredit);
        return new ResponseData("200", "添加成功");
    }

    @GetMapping("/selectActiveCreditList")
    public ResponseData selectActiveTypeList(ActCredit actCredit) {
        List<ActCredit> activeCreditList = activeCreditService.selectActiveCreditList(actCredit);
        return new ResponseData("200", "查询成功",activeCreditList);
    }

    @GetMapping("/selectPage")
    public ResponseData selectPage(
            ActCredit actCredit,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize
    ) {
        PageInfo<ActCredit> activeCreditPageInfo = activeCreditService.selectPage(actCredit,pageNum, pageSize);
        return new ResponseData("200", "查询成功",activeCreditPageInfo);
    }

    @PutMapping("/updateActiveCredit")
    public ResponseData updateActiveCredit(@RequestBody ActCredit actCredit) {
        activeCreditService.updateActiveCredit(actCredit);
        return new ResponseData("200", "修改成功");
    }

    /**
     * 逻辑删除
     */
    @PutMapping("/deleteActiveCredit/{actId}")
    public ResponseData deleteActiveCredit(@PathVariable Long actId, @RequestParam String updateBy) {
        activeCreditService.deleteActiveCredit(actId, updateBy);
        return new ResponseData("200", "删除成功");
    }

    /**
     * 批量删除
     * @param
     * @return
     */
    @PutMapping("/deleteActiveCreditBatch/{updateBy}")
    public ResponseData deleteBatch(
            @PathVariable String updateBy,
            @RequestBody List<Long> ids
    ){
        System.out.println(ids);
        activeCreditService.deleteBatch(ids,updateBy);
        return new ResponseData("200", "批量删除成功");
    }
}
